package com.lhz.project.wage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.lhz.common.page.ResponseObject;
import com.lhz.framework.aspect.log.annotation.SysLog;
import com.lhz.framework.security.annotation.CheckPermission;
import com.lhz.framework.security.annotation.IgnoreToken;
import com.lhz.project.system.model.entity.dept.Dept;
import com.lhz.project.wage.model.entity.WageBase;
import com.lhz.project.wage.model.entity.WageWeal;
import com.lhz.project.wage.service.WageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LiHuaZhi
 * @since 2020-07-04 13:08:44
 */
@Tag(name = "工资管理")
@RestController
@RequestMapping("wageBase")
@ApiSort(10)
public class WageController {


    @Resource
    private WageService wageService;

    @IgnoreToken
    @Operation(summary = "下载基础模板", description = "下载基础模板")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = WageBase.class))))
    @ApiOperationSupport(order = 5)
    @SysLog(model = "工资管理", name = "下载基础模板")
    @GetMapping("/down/base")
    public void downloadBaseExcel(HttpServletRequest request, HttpServletResponse response) {
        wageService.downloadBaseExcel(request, response);
    }

    @Operation(summary = "查询列表", description = "查询列表")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = WageBase.class))))
    @ApiOperationSupport(order = 10)
    @SysLog(model = "工资管理", name = "查询列表")
    @CheckPermission(code = "wage:wage:query")
    @GetMapping
    public ResponseObject listWageBase() {
        //查询基础工资
        List<WageBase> baseList = wageService.listWageBase();
        //查询福利工资
        List<WageWeal> wealList = wageService.listWageWeal();
        //封装为map
        Map<String, Object> map = new HashMap<>();
        map.put("base", baseList);
        map.put("weal", wealList);

        return ResponseObject.success(map);
    }


    @Operation(summary = "基础导入", description = "基础导入")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = WageBase.class))))
    @ApiOperationSupport(order = 15)
    @Parameters({
            @Parameter(name = "file", description = "文件", required = true, schema = @Schema(name = "file", format = "binary"))
    })
    @SysLog(model = "工资管理", name = "基础导入")
    @CheckPermission(code = "wage:base:import")
    @PostMapping("/base")
    public ResponseObject uploadBaseExcel(@RequestParam("file") MultipartFile file) throws Exception {
        wageService.uploadBaseExcel(file);
        return ResponseObject.success();
    }

    @Operation(summary = "福利导入", description = "福利导入")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = WageBase.class))))
    @ApiOperationSupport(order = 20)
    @Parameters({
            @Parameter(name = "file", description = "文件", required = true, schema = @Schema(name = "file", format = "binary"))
    })
    @SysLog(model = "工资管理", name = "福利导入")
    @CheckPermission(code = "wage:weal:import")
    @PostMapping("/weal")
    public ResponseObject uploadWealExcel(@RequestParam("file") MultipartFile file) throws Exception {
        wageService.uploadWealExcel(file);
        return ResponseObject.success();
    }

    //导出
    @IgnoreToken
    @Operation(summary = "工资导出", description = "工资导出")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Dept.class))))
    @ApiOperationSupport(order = 25)
    @SysLog(model = "工资管理", name = "工资导出")
    @CheckPermission(code = "wage:weal:output")
    @GetMapping("/out")
    public void outWageExcel(HttpServletResponse response) {
        wageService.outWageExcel(response);
    }
}